﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Input;

using SBPweb.RIA.Client.Controls.Base;

using SBPweb.PlAzureNet.Shared.Library.Actors;

using SBPweb.PlAzureNet.Client.Library;
using SBPweb.PlAzureNet.Client.Library.Controls;
using SBPweb.PlAzureNet.Client.Library.Controllers;
using SBPweb.PlAzureNet.Client.Library.Services.Data;

using SBPweb.PlAzureNet.Client.Modules.Facebook.API;

namespace SBPweb.PlAzureNet.Client.Modules.Facebook.Controls
{

    public partial class MainControl : UserControlBase
    {

        public MainControl()
        {
            Connector.Instance.Dispatcher = this.Dispatcher;

            InitializeComponent();

            SetValue(ModuleLoader.ControlPlacementProperty, ControlPlacements.PlaceHolder);
            SetValue(ModuleLoader.ControlPlacementArgumentProperty, "cpSocialContent");

            Loaded += new RoutedEventHandler(MainControl_Loaded);
            Unloaded += new RoutedEventHandler(MainControl_Unloaded);
            Connector.Instance.LoggedIn += new EventHandler(Connector_LoggedIn);
        }

        private void MainControl_Loaded(object sender, RoutedEventArgs e)
        {
            Connector.Instance.Login();
        }

        private void MainControl_Unloaded(object sender, RoutedEventArgs e)
        {
            Connector.Instance.Logout();
        }

        private void Connector_LoggedIn(object sender, EventArgs e)
        {
            Type t = typeof(User);
            User user = Connector.Instance.User as User;

            imgFace.Source = new BitmapImage(user.AvatarUri);
            if (user.Gender != Genders.Unknown)
            {
                imgGender.Source = t.GetEmbeddedBitmapImage(string.Format("Resources.{0}_100x100.png", user.Gender.ToString()));
            }
            tbkName.Text = user.FullName;
        }

    }

}